{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true,
    "pycharm": {
     "is_executing": true
    }
   },
   "outputs": [],
   "source": [
    "import faiss\n",
    "\n",
    "print(faiss.__version__)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.9935,0.4876,0.8173,0.4158,0.53,0.0851,0.9867,0.6719,0.5254,0.1003,0.0948,0.3675,0.446,0.5096,0.8411,0.0214,0.0854,0.3523,0.2715,0.8733,0.8422,0.8907,0.5477,0.1,0.3201,0.5676,0.2157,0.5002,0.6604,0.1665,0.8243,0.5747,0.8654,0.7355,0.5812,0.52,0.089,0.9661,0.5624,0.8674,0.8112,0.6349,0.1698,0.5581,0.8631,0.6946,0.5624,0.454,0.2481,0.3658,0.6857,0.7083,0.357,0.349,0.197,0.8507,0.1238,0.7191,0.9684,0.6668,0.0698,0.4068,0.8566,0.3142\n"
     ]
    }
   ],
   "source": [
    "# 生成随机向量\n",
    "import numpy as np\n",
    "\n",
    "random_vector = np.round(np.random.rand(64), 4)\n",
    "print(','.join(map(str, random_vector)))\n"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "defaultdict(<class 'list'>, {'a': [1], 'b': [2]})\n"
     ]
    }
   ],
   "source": [
    "from collections import defaultdict\n",
    "\n",
    "# 测试dict\n",
    "data = defaultdict(list)\n",
    "\n",
    "data['a'].append(1)\n",
    "data['b'].append(2)\n",
    "\n",
    "print(data)"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "defaultdict(<function <lambda> at 0x1041aeca0>, {'t1': ([1, 2], [[1.0, 2.0, 3.0], [1.1, 2.1, 3.1]]), 't2': ([5, 6], [[1.5, 2.5, 3.5], [1.6, 2.6, 3.6]])})\n"
     ]
    }
   ],
   "source": [
    "from typing import Dict\n",
    "from typing import Tuple\n",
    "from collections import defaultdict\n",
    "\n",
    "tag_dict: Dict[str, Tuple[list, list]] = defaultdict(lambda: (list(), list()))\n",
    "\n",
    "tag_dict['t1'][0].append(1)\n",
    "tag_dict['t1'][1].append([1.0, 2.0, 3.0])\n",
    "\n",
    "tag_dict['t1'][0].append(2)\n",
    "tag_dict['t1'][1].append([1.1, 2.1, 3.1])\n",
    "\n",
    "tag_dict['t2'][0].append(5)\n",
    "tag_dict['t2'][1].append([1.5, 2.5, 3.5])\n",
    "\n",
    "tag_dict['t2'][0].append(6)\n",
    "tag_dict['t2'][1].append([1.6, 2.6, 3.6])\n",
    "\n",
    "print(tag_dict)"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a red\n",
      "b yellow\n",
      "c red\n"
     ]
    }
   ],
   "source": [
    "from abc import ABC\n",
    "from typing import Dict\n",
    "\n",
    "\n",
    "class Fruit(ABC):\n",
    "    def color(self) -> str:\n",
    "        pass\n",
    "\n",
    "\n",
    "class Apple(Fruit):\n",
    "    def color(self) -> str:\n",
    "        return 'red'\n",
    "\n",
    "\n",
    "class Banana(Fruit):\n",
    "    def color(self) -> str:\n",
    "        return 'yellow'\n",
    "\n",
    "\n",
    "d: Dict[str, Fruit] = {'a': Apple(), 'b': Banana()}\n",
    "\n",
    "d['c'] = Apple()\n",
    "\n",
    "for k, v in d.items():\n",
    "    print(k, v.color())\n",
    "\n"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "from typing import TypedDict, NotRequired\n",
    "\n",
    "\n",
    "class BookDict(TypedDict):\n",
    "    isbn: str\n",
    "    title: str\n",
    "    authors: list[str]\n",
    "    pagecount: NotRequired[int]\n",
    "\n",
    "\n",
    "bd: BookDict = {\n",
    "    'isbn': '0201657880',\n",
    "    'title': 'Programming Pearls',\n",
    "    'authors': ['Jon Bentley'],\n",
    "    'pagecount': 1,\n",
    "}\n",
    "\n"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[Person: Alice, Age: 30, Person: Bob, Age: 25, Person: Charlie, Age: 35]\n"
     ]
    }
   ],
   "source": [
    "class Person:\n",
    "    def __init__(self, name, age):\n",
    "        self.name = name\n",
    "        self.age = age\n",
    "\n",
    "    def __str__(self):\n",
    "        return f\"Person: {self.name}, Age: {self.age}\"\n",
    "\n",
    "    def __repr__(self):\n",
    "        return self.__str__()\n",
    "\n",
    "\n",
    "# 创建包含 Person 对象的列表\n",
    "person_list = [Person(\"Alice\", 30), Person(\"Bob\", 25), Person(\"Charlie\", 35)]\n",
    "\n",
    "# 打印列表\n",
    "print(person_list)"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
